package com.wechat.weibo.service;

import com.wechat.weibo.dao.CommentDao;
import com.wechat.weibo.dao.UserDao;
import com.wechat.weibo.dao.WeiboDao;
import com.wechat.weibo.entity.Comment;
import com.wechat.weibo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentService {
    @Autowired(required = false)
    CommentDao commentDao;
    @Autowired(required = false)
    UserDao userDao;
    @Autowired(required = false)
    WeiboDao weiboDao;

    public List<Comment> showComment(String selfID, int weibo_id){
        List<Comment> list=commentDao.getComment(weibo_id);
        for (Comment comment :list) {
            User user=userDao.getUser(comment.getHost_openid());
            comment.setHost_img(user.getImg());
            comment.setHost_name(user.getUserName());
        }
        return list;
    }
    public int postComment(User user,int weibo_id, String content){
        Date date=new Date();
        date.setTime(date.getTime()+8*60*60*1000);
        commentDao.post(user,content,date,weibo_id);
        weiboDao.addComment(weibo_id);
        return 0;
    }

}
